home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / love4th.zip / COMPAT83.DOC < prev    next >
Text File  |  1991-10-01  |  4KB  |  109 lines

  1. Love Forth Compatability Notes
  2. ------------------------------
  3. Here are some notes on compatibility between single segment forth 83
  4. systems and Love forth.
  5.  
  6. Storing into CONSTANTs
  7.  
  8. Old:   0 CONSTANT #flower-pots
  9.        44 ' #flower-pots >BODY !
  10.  
  11. Love:  0 CONSTANT #flower-pots
  12.        44 ' #flower-pots TS:>BODY TS:!
  13.  
  14.   In Love Forth, the data cell for CONSTANT is stored in the thread 
  15.   Segment.  TS:! is like ! and TS:>BODY is like >BODY but are directed 
  16.   to the thread segment.
  17.  
  18. Revectoring
  19.  
  20. Old:      : PRINTER-EMIT PRN1-EMIT ;
  21.           ' COM1-EMIT ' PRINTER-EMIT >BODY !
  22.           (where PRN1-EMIT and COM1-EMIT have been previously defined)
  23.  
  24. Love:     ' COM1-EMIT ' PRINTER-EMIT TS:>BODY TS:!
  25.  
  26.   In Love Forth the threaded addresses are changed/stored with TS:! .
  27.   Note that revectoring can more easily be accomplished with the 
  28.   revecoring  word set (REDEFINE, RESTORE,  MAKE_DYNAMIC, GETVECTOR, 
  29.   etc).  See the  documentation of these words for more information.
  30.  
  31. Adding code to the dictionary
  32.  
  33.         Sometimes in compiler words, code or branching offsets are
  34. added to the dictionary with , .  This cannot be used in L.O.V.E. Forth
  35. as , (comma) adds to the variable segment (VS:).    To add to the
  36. thread segment the word TS:, is used.
  37.  
  38.         For example:
  39.         : AGAIN   COMPILE BRANCH  ,     ; IMMEDIATE
  40.  
  41.         becomes:
  42.         : AGAIN   COMPILE BRANCH  TS:,  ; IMMEDIATE
  43.  
  44.         COMPILE and [COMPILE] perform their expected functions.
  45. Compiler words using these will work in L.O.V.E. Forth as in other
  46. forths.  Note that the following standard words are also implemented,
  47. to make control structures easy: <MARK  <RESOLVE  >MARK  >RESOLVE
  48.  
  49.  
  50. CREATE - DOES>
  51.  
  52.   In standard Forth CREATE DOES> words are used both for defining data
  53. structures and for defining run time words (such as CASE statements).
  54. These functions are destinct in Love Forth.
  55.  
  56.   CREATE  DOES> pair at run time returns an address in the VS: as a
  57. parameter field for data storage uses, CREATE:  DOES:> pair at
  58. run-time returns an address in the TS: for use in defining control
  59. structures etc.
  60.  
  61. Example 1.
  62.       ( word to create a byte array )
  63.       : CARRAY CREATE ALLOT             ( comp time: n -- )
  64.       DOES> + ;                         ( run time: n -- addr )
  65.  
  66.       20 CARRAY flower-power
  67.       20 CARRAY flower-tower
  68.       5 flower-power C@  19 flower-tower C!  ( set location 19)
  69.  
  70.       Here there is no change from other standard Forths.
  71.  
  72. Example 2.
  73.       ( a word to make case statements )
  74.       (    it works by fetching a spec'd thread to execute )
  75.       : CASE: CREATE: ] SMUDGE          ( comp time:  -- )
  76.       DOES:> SWAP 2* + TS:@ EXECUTE ;   ( run time: n -- )
  77.  
  78.       CASE: FLOWER-TYPES
  79.             PETUNIA   ROSE    DANDYLION  CHRYSANTHEMUM ;
  80.  
  81.       Here the CREATE: DOES:> pair and TS:@ replace the CREATE DOES>
  82.       and @ from standard Forth.
  83.  
  84. Example 3.
  85.       Note that CREATE alone can still be used for data storage,
  86.       as in other Forths
  87.  
  88.       CREATE #leaves-per-flower
  89.       4 C, 5 C, 1 C, 27 C, 102 C, 7 C,
  90.  
  91.       #leaves-per-flower 4 + C@ .      ( would print 102 )
  92.  
  93.       However if CREATE is used for compiling a list of threads
  94.       CREATE: must be used, and access must be made with TS:@.
  95.  
  96.       CREATE: FLOWER-DESCRIPTIONS ]
  97.          PERRYWINKLE   BATCHELORS-BUTTON  FORGET-ME-NOT [
  98.  
  99.       FLOWER-DESCRIPTIONS 2+ TS:@ EXECUTE
  100.  
  101.       CREATE: and TS:@ replace CREATE and @ from standard Forth.
  102.  
  103. Example 4.
  104.       Love Forth always allots VARIABLEs and DVARIABLEs on an even
  105.       byte boundary (in VS:).  This means that HERE may be increased
  106.       by an extra byte on occation.  To disable this, simply
  107.       re-define VARIABLE and DVARIABLE:
  108.       : VARIABLE  CREATE   2 ALLOT ;
  109.       : DVARIABLE VARIABLE 2 ALLOT ;